;;==========================================================================
;; Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
;;==========================================================================

    AREA |.text|,ALIGN=2,CODE, READONLY

    IMPORT  myChat
    EXPORT  chat
    EXPORT  Getspsr
    EXPORT  GetBankedRegs

chat
    stmdb   sp!, {r0-r12,lr}
    mrs     r0, cpsr

    mov     r1, lr
    add     r2, sp, #0x38    /*fixup sp*/
    stmdb   sp!, {r0-r2}

    orr     r0,r0,#0xC0
    msr     cpsr_cf, r0    /*cli*/

    mov     r0,sp
    bl      myChat

	ldmia	sp!, {r0-r2}
//    bic     r0,r0,#0xC0
    msr     cpsr_cf, r0    /*sti*/

    ldmia   sp!, {r0-r12,lr}

    mov    pc, lr
;#==========================================================================
Getspsr
    mrs     r0, spsr
    mov     pc, lr
;#==========================================================================
// int GetBankedRegs(UINT *bankreg;
GetBankedRegs
    stmdb   sp!, {r1-r3,lr}
    mov   r2, r0 /*get bank reg struct base*/

    mrs     r1,cpsr

    mrs     r0,spsr

    tst     r0,#0x0f
    beq     user_mode

    ORR	 r0, r0, #0xC0   //cli, try to enter banked mode
    msr     cpsr_cxsf,r0 //enter banked mode

    str     r13, [r2]//stackreg
    str     r14, [r2,#4]//linkreg

    msr     cpsr_cxsf,r1 //restoer processor status
    b       getbank_exit

user_mode
    stmia   r2, {r13, r14}^

getbank_exit
    mov     r0, #0  //return success
    ldmia   sp!, {r1-r3,lr}
    mov     pc, lr

    END

